# -*- coding:utf-8 -*-
# @FileName  :dhcc_per_reportlog.py
# @Time      :2020/12/17 16:44
# @Author    :Zhoujirong
# @Desc      :报告使用记录
import time,datetime
from common.log import Log
from biz.cases.base_case import BaseCase
from common.utils import download
from biz.flow.per_reportlog import PerReporlogRequest

class TestPerReportlog(BaseCase):
    data_file_name = 'per_reportlog.yaml'
    @classmethod
    def setUpClass(cls) -> None:
        cls.cookie = BaseCase().get_token()

    def test_a_list(self):
        '''报告使用记录页跳转'''
        ret = PerReporlogRequest.reportlog_list(self.cookie)
        Log.info(ret)
        self.assertIn('报告使用记录列表',ret)

    def get_page(self):
        '''检索-返回一条数据'''
        curPage = self.file_data.get('curPage')
        maxSize = self.file_data.get('maxSize')
        search_EQ_clientName = self.file_data.get('search_EQ_clientName')
        search_EQ_certType = self.file_data.get('search_EQ_certType')
        search_EQ_certNo = self.file_data.get('search_EQ_certNo')
        search_EQ_operateUser = self.file_data.get('search_EQ_operateUser')
        search_EQ_operateDept = self.file_data.get('search_EQ_operateDept')
        search_GTE_LTE_operateDate_DATE_RANGE = '%s - %s'%(datetime.date.today(),datetime.date.today())
        search_EQ_operateType = self.file_data.get('search_EQ_operateType')
        search_EQ_sysCode = self.file_data.get('search_EQ_sysCode')
        search_EQ_queryFormat = '00'
        ret = PerReporlogRequest.get_page(curPage,
                                        maxSize,
                                        search_EQ_clientName,
                                        search_EQ_certType,
                                        search_EQ_certNo,
                                        search_EQ_operateUser,
                                        search_EQ_operateDept,
                                        search_GTE_LTE_operateDate_DATE_RANGE,
                                        search_EQ_operateType,
                                        search_EQ_sysCode,
                                        search_EQ_queryFormat, self.cookie)
        Log.info(ret)
        self.assertIsNotNone(ret.list)
        return ret.list[0]

    def detail(self):
        '''跳转详情'''
        id = self.get_page().id
        ret = PerReporlogRequest.detail(id,self.cookie)
        Log.info(ret)
        self.assertIn('报告使用记录详情',ret)
        return id

    def test_b_findbyid(self):
        '''详情'''
        id = self.detail()
        ret = PerReporlogRequest.findbyid(id,self.cookie)
        Log.info(ret)
        self.assertEqual(id,ret.id)

    def test_c_exportload_one(self):
        '''导出一条数据'''
        search_EQ_clientName = self.file_data.get('search_EQ_clientName')
        search_EQ_certType = self.file_data.get('search_EQ_certType')
        search_EQ_certNo = self.file_data.get('search_EQ_certNo')
        search_EQ_operateUser = self.file_data.get('search_EQ_operateUser')
        search_EQ_operateDept = self.file_data.get('search_EQ_operateDept')
        search_EQ_operateType = self.file_data.get('search_EQ_operateType')
        search_EQ_sysCode = self.file_data.get('search_EQ_sysCode')
        search_EQ_queryFormat = '00'
        search_GTE_LTE_operateDate_DATE_RANGE = '%s - %s'%(datetime.date.today(),datetime.date.today())
        ids = self.get_page().id
        ret = PerReporlogRequest.exportload(search_EQ_clientName,
                                            search_EQ_certType,
                                            search_EQ_certNo,
                                            search_EQ_operateUser,
                                            search_EQ_operateDept,
                                            search_GTE_LTE_operateDate_DATE_RANGE,
                                            search_EQ_operateType,
                                            search_EQ_sysCode,
                                            search_EQ_queryFormat,
                                            ids, self.cookie)
        time.sleep(5)
        Log.info(ret)
        name = '个人报告使用记录1条dhcc_per_reportlogDtest_c_exportload_one%s.xls'%time.strftime('%Y%m%d%H%M%S',time.localtime())
        size = download(name,ret)
        Log.info('文件大小为:%s' % size)
        self.assertNotEqual(0, size)

    def get_page_more(self):
        '''检索-返回多条数据'''
        curPage = self.file_data.get('curPage')
        maxSize = self.file_data.get('maxSize')
        search_EQ_clientName = ''
        search_EQ_certType = ''
        search_EQ_certNo = ''
        search_EQ_operateUser  = ''
        search_EQ_operateDept = ''
        search_EQ_operateType = ''
        search_EQ_sysCode  = ''
        search_EQ_queryFormat = ''
        search_GTE_LTE_operateDate_DATE_RANGE = ''
        ret = PerReporlogRequest.get_page(curPage,
                                        maxSize,
                                        search_EQ_clientName,
                                        search_EQ_certType,
                                        search_EQ_certNo,
                                        search_EQ_operateUser,
                                        search_EQ_operateDept,
                                        search_GTE_LTE_operateDate_DATE_RANGE,
                                        search_EQ_operateType,
                                        search_EQ_sysCode,
                                        search_EQ_queryFormat, self.cookie)
        Log.info(ret)
        self.assertIsNotNone(ret.list)
        return ret.list

    def id_data_more(self):
        ids_list = []
        datas = self.get_page_more()
        for data in datas:
            ids_list.append(data.id)
        ids = ids_list[:2]
        ids = ','.join(ids)
        return ids

    def test_d_exportload_more(self):
        '''导出2条数据'''
        search_EQ_clientName = ''
        search_EQ_certType = ''
        search_EQ_certNo = ''
        search_EQ_operateUser = ''
        search_EQ_operateDept = ''
        search_EQ_operateType = ''
        search_EQ_sysCode = ''
        search_EQ_queryFormat = ''
        search_GTE_LTE_operateDate_DATE_RANGE = ''
        ids = self.id_data_more()
        ret = PerReporlogRequest.exportload(search_EQ_clientName,
                                            search_EQ_certType,
                                            search_EQ_certNo,
                                            search_EQ_operateUser,
                                            search_EQ_operateDept,
                                            search_GTE_LTE_operateDate_DATE_RANGE,
                                            search_EQ_operateType,
                                            search_EQ_sysCode,
                                            search_EQ_queryFormat,
                                            ids, self.cookie)
        Log.info(ret)
        self.assertIsNotNone(ret)
        name = '个人报告使用记录2条dhcc_per_reportlogDtest_d_exportload_more%s.xls' % time.strftime('%Y%m%d%H%M%S', time.localtime())
        size = download(name, ret)
        Log.info('文件大小为:%s' % size)
        self.assertNotEqual(0, size)

    def test_e_exportload_all(self):
        '''导出全部数据'''
        search_EQ_clientName = ''
        search_EQ_certType = ''
        search_EQ_certNo = ''
        search_EQ_operateUser = ''
        search_EQ_operateDept = ''
        search_EQ_operateType = ''
        search_EQ_sysCode = ''
        search_EQ_queryFormat = ''
        search_GTE_LTE_operateDate_DATE_RANGE = ''
        ids = ''
        ret = PerReporlogRequest.exportload(search_EQ_clientName,
                                            search_EQ_certType,
                                            search_EQ_certNo,
                                            search_EQ_operateUser,
                                            search_EQ_operateDept,
                                            search_GTE_LTE_operateDate_DATE_RANGE,
                                            search_EQ_operateType,
                                            search_EQ_sysCode,
                                            search_EQ_queryFormat,
                                            ids, self.cookie)
        time.sleep(10)
        Log.info(ret)
        self.assertIsNotNone(ret)
        name = '个人报告使用记录alldhcc_per_reportlogDtest_e_exportload_all%s.xls' % time.strftime('%Y%m%d%H%M%S', time.localtime())
        size = download(name, ret)
        Log.info('文件大小为:%s' % size)
        self.assertNotEqual(0, size)





if __name__ == "__main__":
    pass